/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sqlitedb;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author kylin
 */
public class Demo0004_InsertData {
    public static void main(String[] args){
        Connection connection = null;
        try{
            connection = DriverManager.getConnection("jdbc:sqlite:E:\\sample.db");
            Statement statement = connection.createStatement();
            statement.setQueryTimeout(30);
            
            statement.executeUpdate("insert into person values(3, 'kylin')");
            statement.executeUpdate("insert into person values(4, 'chery')");
            ResultSet rs = statement.executeQuery("select * from person");
            while(rs.next()){
              System.out.println("name = " + rs.getString("name"));
              System.out.println("id = " + rs.getInt("id"));
            }
        }catch(SQLException e){
            System.err.println(e.getMessage());
        }finally{
            try{
                if(connection != null){
                    connection.close();
                }
            }catch(SQLException e){
                System.err.println(e);
            }
        }
    }
}
